package client;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.UIManager;
import miscellaneous.Storage;

import client.login.Login;
import client.login.LoginWindow;
import client.main.MainWindow;

public class Client implements PropertyChangeListener {
		
	public static void main(String[] args) {
		new Client();
	}
	
	public Client() {
		try {	
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (Throwable e) {
			e.printStackTrace();
		}
		showLogin();
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		if(evt.getPropertyName().equals("successLogin")) {
			boolean loginSet = Storage.setLogin((Login)evt.getSource());
			if(loginSet) {				
				Receiver.startReceiving();
				MainWindow main = new MainWindow();
				main.setVisible(true);
			}
			else {
				showLogin();
			}
		}
	}
	
	public void showLogin() {
		Login login = new Login();
		login.addPropertyChangeListener(this);
		LoginWindow loginWindow = new LoginWindow(login);
		loginWindow.setVisible(true);
	}
}
